﻿package mortal.game.scene3D.map3D
{
    import baseEngine.core.*;
    import com.gengine.core.frame.*;
    import com.gengine.resource.info.*;
    import flash.utils.*;
    import mortal.game.scene3D.layer3D.*;

    public class MapBitmap3D extends Pivot3D
    {
        private var _referenceCount:int = 0;
        public var disposeTime:Number = -1;
        private var _info:ImageInfo;
        public var isDispose:Boolean = false;
        public var cellTexture:Texture3D;
        public static const DisposeTime:Number = 10000;

        public function MapBitmap3D()
        {
            super("");
            return;
        }// end function

        public function get referenceCount() : int
        {
            return this._referenceCount;
        }// end function

        public function removeReference() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this._referenceCount - 1;
            _loc_1._referenceCount = _loc_2;
            if (this._referenceCount <= 0)
            {
                this.disposeTime = getTimer() + DisposeTime;
            }
            return;
        }// end function

        public function addReference() : void
        {
            if (this._referenceCount < 0)
            {
                this._referenceCount = 0;
            }
            var _loc_1:String = this;
            var _loc_2:* = this._referenceCount + 1;
            _loc_1._referenceCount = _loc_2;
            return;
        }// end function

        public function get info() : ImageInfo
        {
            return this._info;
        }// end function

        public function set info(param1:ImageInfo) : void
        {
            this._info = param1;
            this.isDispose = false;
            this.x = param1.extData.x * MapConst.pieceWidth;
            this.y = param1.extData.y * MapConst.pieceHeight;
            if (param1.isATF)
            {
                if (!this.cellTexture && param1.ATFByteArray)
                {
                    this.cellTexture = new Texture3D(param1.ATFByteArray, Texture3D.MIP_NONE, param1.format);
                }
            }
            else if (!this.cellTexture && param1.bitmapData)
            {
                this.cellTexture = new Texture3D(param1.bitmapData, Texture3D.MIP_NONE);
            }
            return;
        }// end function

        public function get canDispose() : Boolean
        {
            if (this.disposeTime == -1 || FrameManager.flashFrame.getTime() < this.disposeTime)
            {
                return false;
            }
            return true;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            if (this.isDispose)
            {
                return;
            }
            if (parent)
            {
                MapLayer3D(parent).removeMap3dFromStage(this);
            }
            this.isDispose = true;
            this.disposeTime = -1;
            if (this._info)
            {
                this._info.dispose();
                this._info = null;
            }
            if (this.cellTexture != null)
            {
                this.cellTexture.dispose();
                this.cellTexture = null;
            }
            return;
        }// end function

    }
}
